#ifndef SCHEDULER_HPP_
#define SCHEDULER_HPP_

#include "Hal/IHardware.h"
#include "Hal/ITaskContext.h"
#include "Utils/LinkedList.h"
#include "Scheduler/Thread.h"

#if TRACE_SCHEDULER
#define SCHEDULER_TRACE(x ...) TRACE("Scheduler: " x)
#else
#define SCHEDULER_TRACE(x ...)
#endif

#if TRACE_SCHEDULER_DETAILED
#define SCHEDULER_TRACE_DETAILED(x ...) SCHEDULER_TRACE(x)
#else
#define SCHEDULER_TRACE_DETAILED(x ...)
#endif

class Scheduler;
class Session;
class Team;
class Process;
class Thread;

class Spinlock;
class List;

class Scheduler
{
friend class Session;
friend class Team;
friend class Thread;
public:
	static Result Initialize( void );
	static void Schedule( ITaskContext * context );
	static void Yield( void );

	static Thread * GetSystemThread( void );

	static void StartThread( Thread * thread );// { RunningThreads->Add( thread ); };
	static int GetThreadCount( void );// { return RunningThreads->GetCount(); };

	static void DumpThread( Thread * thread );

public:
	static Session * SystemSession;
	static Thread * SystemThread;
	static Session * CurrentSession;
	static Team * CurrentTeam;
	static Process * CurrentProcess;
	static Thread * CurrentThread;
	static List * RunningThreads;

private:
	static Spinlock * SchedulerLock;
};

#endif /*SCHEDULER_HPP_*/
